{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-11-18T18:07:22.776006800Z",
     "start_time": "2023-11-18T18:07:22.760422500Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.4241290368547127\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "num = random.random()\n",
    "print(num)  # 输出0到1之间的随机浮点数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "num = random.randint(1, 10)\n",
    "print(num)  # 输出1到10之间的随机整数"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-18T18:09:21.729289100Z",
     "start_time": "2023-11-18T18:09:21.713664700Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.937942966626033\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "num = random.uniform(2.5, 5.5)\n",
    "print(num)  # 输出2.5到5.5之间的随机浮点数"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-18T18:13:49.212383300Z",
     "start_time": "2023-11-18T18:13:49.208365300Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "num = random.randrange(1, 10, 2)\n",
    "print(num)  # 输出1到10之间的奇数随机整数"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-18T18:13:14.259543500Z",
     "start_time": "2023-11-18T18:13:14.249801900Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "my_list = [1, 2, 3, 4, 5]\n",
    "num = random.choice(my_list)\n",
    "print(num)  # 从列表中随机选择一个元素"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-18T18:15:34.608724800Z",
     "start_time": "2023-11-18T18:15:34.576446500Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 5, 2, 4, 3]\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "my_list = [1, 2, 3, 4, 5]\n",
    "random.shuffle(my_list)\n",
    "print(my_list)  # 输出打乱顺序后的列表"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-18T18:16:58.542884700Z",
     "start_time": "2023-11-18T18:16:58.527089600Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "random.seed(10)  # 设置随机种子为10\n",
    "num = random.randint(1, 10)\n",
    "print(num)  # 输出随机整数，但将得到相同的随机数序列"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-11-18T18:19:55.972890100Z",
     "start_time": "2023-11-18T18:19:55.964070Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
